package vue;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import metier.Gif;

public class MyPanel extends JPanel
{
  private static final long serialVersionUID = -8429909702203504021L;

  private Gif _myGif;
  private BufferedImage _imageBuff;
	private int _x = 0;
	private int _y = 0; 
	private Timer timer;
  
  public MyPanel()
  {
	  try {
		  _imageBuff = ImageIO.read(new File(System.getProperty("user.dir") + "/bin/Ressources/Map.PNG"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	  
	  _myGif = new Gif(System.getProperty("user.dir") + "/bin/Ressources/ninja.gif");
	  this.add(_myGif);
	  
	  timer = new Timer();
	  
	  timer.schedule(new MyTimer(this), 0, 100);
	  
  }
  public void paintComponent(Graphics g) {
      super.paintComponent(g);
      if ( _imageBuff != null )
      {
          g.drawImage(_imageBuff, 0, 0, this);
          g.drawImage(_myGif.getImage(), _x, _y, this);
      }
  }
  

	public Gif getGif() {
		return _myGif;
	}
	
	// Timer use to launch a update at the manager 
	public class MyTimer extends TimerTask {
		MyPanel _panel;
		
		public MyTimer(MyPanel p_panel) {
			super();
			_panel = p_panel;
		}
		
		@Override
		public void run() {
			try {
				_x++;
				_y++;
			} catch (Exception e) {
	            e.printStackTrace();
			}
		}
	}
}